<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<ul id="list">
		<li>1</li>
		<li class="on">2</li>
		<li>3</li>
	</ul>
	<style>	

	</style>
	<script>
		var len1=getByClass('on','list');
		alert(len1.length);
		var len2=getByClass('on');
		alert(len2.length);
		function getByClass(clsName,parent) {
			var boxArr=new Array();
			var oParent=document.getElementById(parent)||document.getElementsByTagName("body")[0];
			// var oParent1=document.getElementsByTagName("body");
			alert(oParent);
			// alert(oParent1);
		
			// var oParent=document.getElementById(parent)||document.getElementById("body");
			var boxs=oParent.getElementsByTagName("*");
			for(var i=0;i<boxs.length;i++){
				if(boxs[i].className==clsName){
					boxArr.push(boxs[i]);
				}
			}
			return boxArr;
		}
	</script>
</body>
</html>